package com.xhs.controller;

import com.xhs.dto.request.SendHttpParam;
import com.xhs.message.ReturnResult;
import com.xhs.service.HttpService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @desc:
 * @projectName: http-test-app
 * @author: xhs
 * @date: 2024-06-10 14:48
 * @version: JDK 1.8
 */
@RestController
@RequestMapping("/test")
public class HttpController {

    @Resource
    private HttpService httpService;

    /**
     * 发送Get请求 无参
     *
     * @return ReturnResult
     */
    @GetMapping("/sendGet")
    public ReturnResult<Object> sendGet() {
        return httpService.sendGet();
    }

    /**
     * 发送Get请求 有参
     *
     * @param httpCode 接口编号
     * @param httpUrl  接口地址
     * @return ReturnResult
     */
    @GetMapping("/sendGetParam")
    public ReturnResult<Object> sendGetParam(String httpCode, String httpUrl) {
        return httpService.sendGetParam(httpCode, httpUrl);
    }

    /**
     * 发送post请求 无参
     *
     * @return ReturnResult
     */
    @PostMapping("/sendPost")
    public ReturnResult<Object> sendPost() {
        return httpService.sendPost();
    }


    /**
     * 发送post请求 有参 json格式
     *
     * @param param 入参
     * @return ReturnResult
     */
    @PostMapping("/sendPostJsonParam")
    public ReturnResult<Object> sendPostJsonParam(@Valid @RequestBody SendHttpParam param) {
        return httpService.sendPostJsonParam(param);
    }

}
